<!DOCTYPE html>
<html>
<head>
    <title>攻略系列</title>
    <audio controls="controls" hidden="hidden" autoplay="autoplay">
        <source src="/music/clcl.mp3" type="audio/mpeg" />
    </audio>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/strategyCatalogs.css"/>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css"/>
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <script src="/js/common.js"></script>
    <script src="/js/checkLogin.js"></script>
    <script src="/css/bight/js/neon_text.js"></script>
    <script src="/js/plugins/jrender/jrender.min.js"></script>

    <script>
        $(function () {
            var params = getParams();
            //根据攻略id查询攻略信息
            $.get(baseUrl + '/strategies/' + params.id, function (data) {
                $(".title").html(data.title);
            })

            //根据攻略id查询攻略分类信息
            $.get(baseUrl + '/strategies/' + params.id + "/catalogs", function (data) {
                var index = 1;
                $(".catalogs").renderValues({list: data}, {
                    getHref: getHref,
                    getName: function (item, value) {
                        $(item).html(index++ + "/" + value);
                    }
                });
            })
            //添加评论按钮
            $("#commentBtn").click(function () {
                window.location.href = "/mine/addComment.html?id="+params.id;
            })

            var currentPage = 1;//默认第一页
            var pages; //总页数
            var travelArr = [];//用户存储游记文章的容器
            var loading = false;//标记是否查询中

            function query() {//分页查询
                if(loading){//代表正在查询,就直接结束方法
                    return;
                }
                loading = true;//标记正在查询中;
                //根据攻略id查询评论信息
                $.get(baseUrl + "/strategies/" + params.id + "/comments",{currentPage:currentPage}, function (data) {
                    $.merge(travelArr,data.list );//合并数据,把第二个参数的数据合并到第一个参数的容器中
                    var json = {list:travelArr};//用于render-loop="list"
                    console.log(json.id);
                    $("#comment").renderValues(json,{
                        getStar:function (item,value) {
                            var temp = '';
                            for (var i = 0; i < value; i++){
                                temp += '<i class="fa fa-star"></i>';
                            }
                            for (var i = 0; i < 5-value; i++){
                                temp += '<i class="fa fa-star-o"></i>';
                            }
                            $(item).html(temp);
                        },
                        //设置当前的大评论id
                        getId: function (item, value) {
                            $(item).attr("data-id", value);
                        }

                    });
                    //点击评论跳转界面事件
                    $('.discussBtn').click(function () {
                        //获取大评论id
                        var id = $(this).data('id');
                        console.log(id);
                        window.location.href="/mine/strategyComment.html?id="+id+"&strategyId=" + params.id

                    })

                    //绑定图片的点击事件
                    $(".comment-img img").click(function () {
                        //获取点击的图片
                        var src = $(this).attr('src');
                        $(document).dialog({
                            style:'ios',
                            titleShow: false,
                            overlayClose: true,
                            content: '<img src="'+src+'" width="100%"/>'
                        });
                    })
                    currentPage++;//当前页数+1
                    pages = data.pages;//设置总页数
                    loading = false;//标记查询结束
                })
            }

            query();//默认查询第一页

            //监听窗口的滚动事件
            $(window).scroll(function () {
                console.log("窗口滚动中...")
                if($(document).scrollTop()+$(window).height()>=$(document).height()){//滚动到底部
                    //如果已经查询到最后一页,就不再查
                    if(currentPage<=pages) {
                        query();
                    }else{
                        $(document).dialog({
                            type : 'notice',
                            content: '<span class="info-text">已经到底了!</span>',
                            autoClose: 1500
                        });
                    }
                }
            })


            //加入我的旅行单的代码
            $("#userStrategy").click(function () {
                if (user) {
                    $.get(baseUrl+"/mytravellists/getTravelList/" + user.id + "/" + params.id, function (data) {
                        console.log(data);
                        if (data.success) {
                            $.ajax({
                                url: baseUrl+"/mytravellists/save/"+user.id+"/"+params.id,
                                method: "POST",
                                success: function (data) {
                                    console.log(data);
                                    $(document).dialog({
                                        autoClose: 1000,
                                        content: '加入成功'
                                    });
                                }
                            });
                        } else {
                            $(document).dialog({
                                autoClose: 1000,
                                content: data.errorMsg,
                            });
                        }
                    });
                } else {
                    $(document).dialog({
                        type: 'confirm',
                        closeBtnShow: true,
                        content: '请登陆后再执行相关操作!',
                        onClickConfirmBtn: function () {
                            window.location.href = "/login.html"
                        }
                    });
                }
            });

        })
    </script>
</head>

<body>
<div class="search-head">
    <div class="row nav-search">
        <div class="col-2">
            <a href="javascript:history.go(-1);">
                <span><i class="fa fa-chevron-left fa-2x"></i></span>
            </a>
        </div>
        <div class="col-10">
            <div class="input-group-sm search">
                <input class="form-control searchBtn" placeholder="搜索旅行攻略">
            </div>
        </div>
    </div>
</div>

<div class="container strategies">
    <h5 class="title">广州攻略</h5>
    <small><span>0</span>人阅读过此攻略</small>
    <div class="focus">
        <i class="fa fa-heart"><span> 0</span> 收藏</i>
        <i class="fa fa-thumbs-up"><span> 0</span> 点赞</i>
        <button class="btn">想去</button>
        <button class="btn">去过</button>
    </div>
</div>
<ul class="nav nav-pills nav-justified border border-left-0 border-top-0 border-right-0" id="pills-tab">
    <li class="nav-item ">
        <a class="nav-link active" id="pills-catalog-tab" data-toggle="pill" href="#pills-catalog">
            <span>攻略目录</span>
        </a>
    </li>
    <li class="nav-item">
        <a class="nav-link " id="pills-comment-tab" data-toggle="pill" href="#pills-comment">
            <span>骡友点评</span>
        </a>
    </li>
</ul>
<div class="tab-content " id="pills-tabContent">
    <div class="tab-pane fade show active" id="pills-catalog">

        <div class="catalogs">
            <div render-loop="list">
                <div class="container detail">
                    <h6 render-key="list.name" render-fun="getName"></h6>
                    <div render-loop="list.details">
                        <a data-url="strategyDetails.html?id=" render-key="list.details.id" render-fun="getHref">
                            <button class="btn" render-html="list.details.title"></button>
                        </a>
                    </div>
                </div>
            </div>
        </div>

    </div>
    <div class="tab-pane fade " id="pills-comment">

        <div class="container tag">
            <h6>骡友标签</h6>
            <div>
                <span>价格便宜</span>
                <span>很热闹</span>
                <span>交通方便</span>
                <span>吃的很多</span>
                <span>风景优美</span>
                <span>美食很多</span>

            </div>
        </div>
        <hr>

        <div id="comment">
            <div render-loop="list">
                <div class="container row comment">
                    <div class="col-2 comment-head">
                        <a href="userProfiles.html">
                            <img class="rounded-circle"
                                 render-src="list.user.headImgUrl">
                        </a>
                    </div>
                    <div class="col comment-right">
                        <p class="authorName"><span render-html="list.user.nickName"></span></p>
                        <span class="comment-star" render-key="list.starNum" render-fun="getStar">

                        </span>
                        <span class="comment-date" render-html="list.createTime">2018-07-19</span>
                        <div class="comment-content">
                            <a href="strategyComment.html">
                                <p render-html="list.content"></p>
                            </a>
                        </div>

                        <ul class="comment-img" render-loop="list.imgUrlsArr">
                            <li>
                                <img render-src="list.imgUrlsArr.self">
                            </li>
                        </ul>

                        <div class="d-flex icon">
                            <!--list.do,大评论的id-->
                            <a >
                                <i class="fa  fa-commenting-o discussBtn" style="margin-right: 10px"
                                   render-key="list.id" render-fun="getId"> 评论 </i>
                                <i class="fa fa-thumbs-o-up"> <span>0</span> </i>
                            </a>
                        </div>

                    </div>
                </div>

            </div>
        </div>
    </div>

</div>
</div>

<div class="operation">
    <button class="btn" id="userStrategy">加入旅行单</button>
    <button class="btn" id="commentBtn">点评</button>
</div>


</body>
</html>